<?php
session_save_path('sessions');
session_start();

include("include/dbUserTypes.php");

// Include our user class
include_once("include/user.php");

// Create a variable to store our user if we're validated
$user = null;

// Check if we're in a valid session. If not, go back to main login page.

if( !isset($_SESSION['user']) || $_SESSION['user'] == null ) {
    header("location:main_login.php");
}
else {
    // Unserialize our user to turn it back into a useful object
    $user = unserialize($_SESSION['user']);
}

// If we're not a registered (or admin) go back to the user redirection page
if( $user->getUserType() != $USERTYPE_REGISTERED && $user->getUserType() != $USERTYPE_ADMIN)
    header("location:login_success.php");


// Include the header (CSS files, etc)
include("include/header.php"); ?>
 

<body>
  <div id="wrapper">
    <div id="header"> </div>
    <div id="left">
      <div id="logo">
        <h1>Home Sale</h1>
        <p>Only By Owner</p>
      </div>
      <div id="nav">
        <ul>
          <li class="important">
            <a href="addAhomeForSale.php">Add a House for sale</a>
          </li>
          <li>
            <a href="updateAhome.php">Update House information</a>
          </li>
          <li >
            <a href="updateAhomePicture.php">Update House picture</a>
          </li>
          <li>
              <a href="searchhouse.php">Search House</a>
          </li>
          <li>
            <a href="emailMenu.php">Mailbox</a>
          </li>
          <li>
            <a href="logout.php">Logout</a>
          </li>
        </ul>
      </div>
      <div id="news">
        <?php include("adgeneratorleft1.php");?>
        <div class="hr-dots"> </div>
        <?php include("adgeneratorleft2.php");?>
      </div>
      <div id="support">
      </div>
    </div>
    <div id="right">
      <h2>Adding a House for sale</h2>
      <div id="welcome">
               
	<table>
   <form name="myForm" action="addAhomeValidate.php" method="post" onsubmit="return validate()">
	<tr><td>Address:</td><td><input type="text" name="address" /></td></tr>
	<tr><td>Street Name:</td><td><input type="text" name="streetName" /></td></tr>
	<tr><td>City:</td><td><input type="text" name="city" /></td></tr>
	<tr><td>Country:</td><td><input type="text" name="country" /></td></tr>
	<tr><td>District:</td><td><input type="text" name="district" /></td></tr>
	<tr><td>Zone:</td><td><input type="text" name="zone" /></td></tr>
	<tr><td>Postal Code:</td><td><input type="text" name="postalCode" /></td></tr>
	<tr><td>Size of lot:</td><td><input type="text" name="lotSize" /></td></tr>

	<tr><td>Type of property:</td><td>

	 <select name="propertyType">
                    <option value="1">Condo</option>
                    <option value="2">Apartment</option>
                    <option value="3">Single family</option>
                    <option value="4">Cottage</option> 
                  </select></td></tr>



	<tr><td>Year built:</td><td><input type="text" name="yearBuilt" /></td></tr>
	<tr><td>Heating</td></tr>
	<tr><td><input type="radio" name="heating" value="1" /> Yes</td><td><input type="radio" name="heating" value="0" />No</td></tr>
	<tr><td>Cooling</td></tr>
	<tr><td><input type="radio" name="cooling" value="1" /> Yes</td><td><input type="radio" name="cooling" value="0" />No</td></tr>
	<tr><td>Parking</td</tr>
	<tr><td><input type="radio" name="parking" value="1" /> Yes</td><td><input type="radio" name="parking" value="0" />No</td></tr>
	<tr><td>Garage</td></tr>
	<tr><td><input type="radio" name="garage" value="1" /> Yes</td><td><input type="radio" name="garage" value="0" />No</td></tr>
	<tr><td>Driveway</td></tr>
	<tr><td><input type="radio" name="driveway" value="1" /> Yes</td><td><input type="radio" name="driveway" value="0" />No</td></tr>
	<tr><td>Neighbourhood:</td><td><input type="text" name="neighbourhood" /></td></tr>
	<tr><td>Recent Improvements:</td><td><input type="text" name="recentImprovements" /></td></tr>
	<tr><td>Evaluated Price:</td><td><input type="text" name="evaluation" /></td></tr>
	<tr><td>Property Taxes:</td><td><input type="text" name="taxes" /></td></tr>
	<tr><td>Utility Cost:</td><td><input type="text" name="utilityCost" /></td></tr>
	<tr><td>Price:</td><td><input type="text" name="price" /></td></tr>

	   <tr>
		   <td>Comments:</td>
		   <td>
			   <textarea rows="5" cols="20" name="comments" wrap="physical" style="width:327px; height:129px;"></textarea>
		   </td>
	   </tr>
	   
  <tr><td><input type="submit" value="Add a House" /></td><td><input type="reset" /></td></tr>
  </table>


	<SCRIPT>


		function is_int(input)
		{
			return !isNaN(input)&&parseInt(input)==input;
		}

		function validate() 
		{
			mNv=myForm.address.value;
			if (mNv=='') 
			{
				alert('The address of the house is a required field.');
				return false;
			}
			if (!is_int(mNv))
			{
				alert('The Address has to be a number.');
				return false;
			}
			mNv=myForm.streetName.value;
			if (mNv=='') 
			{
				alert('The Street Name is a required field.');
				return false;
			}
			mNv=myForm.city.value;
			if (mNv=='') 
			{
				alert('The City in which the house is a required field.');
				return false;
			}
			mNv=myForm.country.value;
			if (mNv=='') 
			{
				alert('The Country in which the house is a required field.');
				return false;
			}
			mNv=myForm.district.value;
			if (mNv=='') 
			{
				alert('The District in which the house is a required field.');
				return false;
			}
			mNv=myForm.zone.value;
			if (mNv=='') 
			{
				alert('The zone in which the house is a required field.');
				return false;
			}
			mNv=myForm.postalCode.value;
			if (mNv=='') 
			{
				alert('The Postal Code the house is a required field.');
				return false;
			}
			mNv=myForm.lotSize.value;
			if (mNv=='') 
			{
				alert('The Size of lot is a required field.');
				return false;
			}
			if (!is_int(mNv))
			{
				alert('The Size of lot has to be a number.');
				return false;
			}
			mNv=myForm.propertyType.value;
			if (mNv=='') 
			{
				alert('The Type of property is a required field.');
				return false;
			}
			if (!is_int(mNv))
			{
				alert('The Type of roperty has to be a number.');
				return false;
			}
			mNv=myForm.yearBuilt.value;
			if (mNv=='') 
			{
				alert('The Year built is a required field.');
				return false;
			}
			if (!is_int(mNv))
			{
				alert('The Year built has to be a number.');
				return false;
			}
			if (!(myForm.heating[0].checked || myForm.heating[1].checked)) {
				alert('You have to specify if there is heating.');
				return false;
			}
			if (!(myForm.cooling[0].checked || myForm.cooling[1].checked)) {
				alert('You have to specify if there is cooling.');
				return false;
			}
			if (!(myForm.parking[0].checked || myForm.parking[1].checked)) {
				alert('You have to specify if there is a parking.');
				return false;
			}
			if (!(myForm.garage[0].checked || myForm.garage[1].checked)) {
				alert('You have to specify if there is a garage.');
				return false;
			}
			if (!(myForm.driveway[0].checked || myForm.driveway[1].checked)) {
				alert('You have to specify if there is a driveway.');
				return false;
			}
			mNv=myForm.neighbourhood.value;
			if (mNv=='') 
			{
				alert('You have tell in which neighbourhood this house is.');
				return false;
			}
			mNv=myForm.evaluation.value;
			if (mNv=='') 
			{
				alert('You have to give the Evaluated price');
				return false;
			}if (!is_int(mNv))
			{
				alert('The Evaluated price has to be a number.');
				return false;
			}
			mNv=myForm.taxes.value;
			if (mNv=='') 
			{
				alert('You have to specify the Property Taxes.');
				return false;
			}
			if (!is_int(mNv))
			{
				alert('The Property Taxes has to be a number.');
				return false;
			}
			mNv=myForm.utilityCost.value;
			if (mNv=='') 
			{
				alert('You have to specify the Utility cost.');
				return false;
			}
			if (!is_int(mNv))
			{
				alert('The Utility cost has to be a number.');
				return false;
			}
			mNv=myForm.price.value;
			if (mNv=='') 
			{
				alert('You have to specify the the house Price.');
				return false;
			}
			if (!is_int(mNv))
			{
				alert('The house Price has to be a number.');
				return false;
			}
			else
				return true;				
		}
	</SCRIPT>
	
	
		


      </div>
      <h3></h3>
      <div id="profile">
        <div id="corp">
          <?php include("adgeneratorbottomleft.php");?>
        </div>
        <div id="indu">
          <?php include("adgeneratorbottomright.php");?>
        </div>
      </div>
    </div>
    <div class="clear"> </div>
    <div id="spacer"> </div>
    <div id="footer">
      <div id="copyright">
        &copy; Template taken from http://www.freewebsitetemplates.com/
      </div>
	  <div id="footerline"></div>
    </div>
	
  </div>
</body>
</html>

